import { $axios } from '@/utils/axios.js';

// 登录
export function login(name, pwd) {
    const data = {
        name, pwd
    };
    return $axios.post('/login', data);
}

// 注册
export function register(name, pwd) {
    const data = {
        name, pwd
    };
    return $axios.post('/register', data);
}

// 退出登录
export function logout() {
    return $axios.post('/logout');
}

// 7 用户信息请求
export function userInfo(name) {
    return $axios.post('/user_info', {name}).then(res => {
        const newData = [];
        const oldData = res.data;
        for (let i = 0; i < oldData.module.length; ++i) {
            newData.push({
                module: oldData.module[i],
                position: oldData.module_position[i] === 'leader' ? '负责人' : '成员',
            });
        }
        res.data = newData;
        return Promise.resolve(res);
    });
}